package com.spark.trouble

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.blankj.utilcode.util.LogUtils
import com.spark.common.BaseActivity
import com.spark.trouble.agency.HTAgencyFragment
import me.yokeyword.fragmentation.SupportFragment

class HTAgencyActivity : BaseActivity() {
    companion object {
        fun actionStart(host: Activity, data: String) {
            val intent = Intent(host, HTAgencyActivity::class.java)
            intent.putExtra("data", data)
            host.startActivity(intent)
        }
    }

    override fun contentResId(): Int {
        return R.layout.act_container
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        intent?.apply {
            getStringExtra("data")?.apply {
                loadRootFragment(R.id.fl_content, HTAgencyFragment.newInstance(this))
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        supportFragmentManager.fragments.forEach {
            LogUtils.e(it.javaClass.canonicalName)
            (it as SupportFragment).onFragmentResult(requestCode, resultCode, data?.extras)
            if (it is RectifyFragment) {
                it.onFileChooseResult(requestCode, resultCode, data)
            }
        }
    }
}